{include file="header.html"}
<div id="main">
	{include file="menus.html"}
	<div id="rightCon" class="clearfix layui-body">
		<div class="scroller">
			<div class="search-form clearfix">
				<form method="get" id="formSearch">
					<div class="webkit-box box-align-center">
						<input type="hidden" name="r" value="distribute/merchant" />
						{$lang.username}
						<input class="queryInput" type="text" name="username" value="{$smarty.get.username|escape}" />
						联系电话
						<input class="queryInput" type="text" name="phone_mob" value="{$smarty.get.phone_mob|escape}" />
						分销店名
						<input class="infoTableInput ml10 mr10" type="text" name="name"
							value="{$smarty.get.name|escape}" />
						邀请人
						<input class="queryInput" type="text" name="parent" value="{$smarty.get.parent|escape}" />
						<label>{$lang.status}</label>
						<select name="status" class="querySelect">
							<option value="" {if $smarty.get.status eq '' } selected{/if}>{$lang.no_limit}</option>
							<option value="1" {if $smarty.get.status eq '1' } selected{/if}>{$lang.open}</option>
							<option value="2" {if $smarty.get.status eq '2' } selected{/if}>{$lang.close}</option>
						</select>
						<input type="submit" class="layui-btn layui-bg-blue layui-btn-sm block width7"
							value="{$lang.query}" />
						<!--{if $filtered}-->
						<a class="layui-btn layui-btn-primary layui-btn-sm box-align-center"
							href="{url route='distribute/merchant'}">{$lang.cancel_query}</a>
						<!--{/if}-->
					</div>
				</form>
			</div>
			<div class="tablegrid">
				<table class="layui-hide" id="tablegrid" lay-filter="tablegrid"></table>
			</div>
			{include file="version.html"}
		</div>
	</div>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
		<button class="layui-btn layui-bg-blue" lay-event="batdel"><i class="layui-icon layui-icon-close"></i>批量删除</button>
		<button class="layui-btn layui-btn-primary layui-border-black" lay-event="export"><i class="layui-icon layui-icon-export"></i>导出数据</button>
	</div>
</script>

<script>
	layui.use('table', function () {
		var table = layui.table;

		table.render({
			elem: '#tablegrid'
			//,skin: 'line'
			, url: url(['distribute/merchant', $("#formSearch").serializeJson()])
			, toolbar: '#toolbar'
			, defaultToolbar: ['filter', /*'exports',*/ 'print']
			, title: '分销商列表'
			//, size: 'lg'
			, cols: [[
				{ type: 'checkbox', fixed: 'left' }
				, { field: 'dmid', title: 'ID', width: 70, fixed: 'left', unresize: true, sort: true }
				, { field: 'username', title: '用户名', width: 200 }
				, { field: 'phone_mob', title: '联系电话', width: 200 }
				, { field: 'name', title: '分销店名', width: 201 }
				, {
					field: 'parent', title: '邀请人', width: 200, sort: true, templet: function (res) {
						return res.parent ? res.parent : '无';
					}
				}
				, { field: 'created', title: '申请时间', width: 180, sort: true, align: 'center' }
				, { fixed: 'right', field: 'status', title: '状态', width: 160 }
			]]
			, page: {
				theme: 'blue'
			}
		});

		//监听头工具栏事件
		table.on('toolbar(tablegrid)', function (obj) {
			var checkStatus = table.checkStatus(obj.config.id);
			if (checkStatus.data.length <= 0) {
				return false;
			}
			var items = new Array();
			$.each(checkStatus.data, function (i, item) {
				items.push(item.dmid);
			});
			if (obj.event === 'batdel') {
				var btnObj = $('[lay-event="' + obj.event + '"]');
				btnObj.attr('confirm', '删除后将不能恢复，确认删除这 ' + items.length + ' 项吗？');
				ajaxRequest(btnObj, url(['distribute/delete', { id: items.join(',') }]), function () {
					table.reload('tablegrid');
				});
			}
			else if (obj.event === 'export') {
				window.location.href = url(['distribute/export', $.extend($("#formSearch").serializeJson(), { id: items.join(',') })]);
			}
		});
	});
</script>
{include file="footer.html"}